package com.example.administrator.x3picturetransliteration.Home.Adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.x3picturetransliteration.Base.BaseListViewAdapter;
import com.example.administrator.x3picturetransliteration.Bean.feedbackListBean;
import com.example.administrator.x3picturetransliteration.R;
import com.example.administrator.x3picturetransliteration.Util.Img.PicassoEqualProportionTransformation2;
import com.example.administrator.x3picturetransliteration.Util.Img.TailorImageView;
import com.squareup.picasso.Picasso;

import java.util.Arrays;
import java.util.List;

/**
 * 反馈记录
 * Created by Administrator on 2019/8/28.
 */

public class FeedbackRecordAdapter extends BaseListViewAdapter{

    private Context context;
    private List<feedbackListBean> mData;
    private hd mhd;

    public FeedbackRecordAdapter(Context context,List<feedbackListBean> mData,hd mhd) {
        super(context);

        this.context = context;
        this.mData = mData;
        this.mhd = mhd;
    }

    @Override
    public int getLayoutView() {
        return R.layout.home_item_feedback_record;
    }

    @Override
    public int mCount() {
        return mData.size();
    }

    @Override
    public void logic(ViewHolder mViewHolder, View view, final int position) {

        IViewHolder mIViewHolder = (IViewHolder)mViewHolder;

        mIViewHolder.imgView1.setVisibility(View.GONE);
        mIViewHolder.imgView2.setVisibility(View.GONE);
        for (ImageView img:mIViewHolder.imgs)img.setVisibility(View.GONE);

        if (mData.get(position).getStatus()==0){

            mIViewHolder.StateText.setText("待处理");
            mIViewHolder.StateText.setTextColor(context.getResources().getColor(R.color.FeedbackRecordTextColor1));
            mIViewHolder.jjfaView.setVisibility(View.GONE);

        }else {

            mIViewHolder.StateText.setText("已解决");
            mIViewHolder.StateText.setTextColor(context.getResources().getColor(R.color.FeedbackRecordTextColor2));
            mIViewHolder.jjfaView.setVisibility(View.VISIBLE);
        }

        mIViewHolder.TimeText.setText(mData.get(position).getGmtCreate());

        mIViewHolder.contentText.setText(mData.get(position).getContent());

        List<String> imgs = Arrays.asList(mData.get(position).getImgs().split(","));

        if (imgs.size()>0)mIViewHolder.imgView1.setVisibility(View.VISIBLE);
        if (imgs.size()>3)mIViewHolder.imgView2.setVisibility(View.VISIBLE);

        for (int i=0;i<imgs.size();i++){

            if (i>=6)return;

            mIViewHolder.imgs[i].setVisibility(View.VISIBLE);

            Picasso.with(context)
                    .load(imgs.get(i))
                    .placeholder(R.drawable.home_advertisement)
                    .error(R.drawable.home_advertisement)
                    .transform(new TailorImageView())
                    .transform(new PicassoEqualProportionTransformation2(mIViewHolder.imgs[i]))
                    .into(mIViewHolder.imgs[i]);

        }

        mIViewHolder.jjfaView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mhd.hdff(mData.get(position).getId());
            }
        });

    }

    @Override
    public ViewHolder InstantiationView(View mview) {

        IViewHolder mIViewHolder = new IViewHolder();

        mIViewHolder.StateText = mview.findViewById(R.id.StateText);
        mIViewHolder.TimeText = mview.findViewById(R.id.TimeText);
        mIViewHolder.contentText = mview.findViewById(R.id.contentText);

        mIViewHolder.jjfaView = mview.findViewById(R.id.jjfaView);

        mIViewHolder.imgView1 = mview.findViewById(R.id.imgView1);
        mIViewHolder.imgView2 = mview.findViewById(R.id.imgView2);

        mIViewHolder.imgs[0] = mview.findViewById(R.id.img1);
        mIViewHolder.imgs[1] = mview.findViewById(R.id.img2);
        mIViewHolder.imgs[2] = mview.findViewById(R.id.img3);
        mIViewHolder.imgs[3] = mview.findViewById(R.id.img4);
        mIViewHolder.imgs[4] = mview.findViewById(R.id.img5);
        mIViewHolder.imgs[5] = mview.findViewById(R.id.img6);

        return mIViewHolder;
    }

    private class IViewHolder extends ViewHolder{

        TextView StateText;
        TextView TimeText;
        TextView contentText;

        View jjfaView;

        View imgView1;
        View imgView2;

        ImageView[] imgs = new ImageView[6];

    }

    public interface hd{

        void hdff(String id);
    }
}
